'use strict';

module.exports = appInfo => {
  const config = {};

  // should change to your own
  config.keys = appInfo.name + '_1493014375701_1710';

  // config.mongoose = {
  //   url: 'mongodb://127.0.0.1/chenlei',
  //   options: {}
  // };

  config.redis = {
    client: {
      cluster: false,
      host: '127.0.0.1',
      port: '6379',
      family: 4,
      password: '',
      db: '',
      keyPrefix: '',
      nodes: [{}]
    }
  };

  // config.redis = {
  //   clients: {
  //     session: { /* config */ },
  //     cache: { /* config */ },
  //   },
  // }

  config.sessionRedis = {
    name: 'session', // specific `session` as the session store
  };

  config.session = {
    key: 'egg-neko',
    maxAge: 24 * 3600 * 1000, // 1 天
    httpOnly: true,
    encrypt: true
  };

  config.mysql = {
    // 单数据库信息配置
    client: {
      // host
      host: 'localhost',
      // 端口号
      port: '3306',
      // 用户名
      user: 'pms_ray',
      // 密码
      password: '',
      // 数据库名
      database: 'pms',
    },
    // 是否加载到 app 上，默认开启
    app: true,
    // 是否加载到 agent 上，默认关闭
    agent: false,
  };

  config.security = {
    csrf: {
      // enable: false,
      ignoreJSON: true,
      ignore: ctx => {
        let [host, port] = (ctx.request.host || '').split(':')

        // console.info(host, ctx.request.host, ctx.request);
        // match all host with '*.chenlei.me' format, and port equals 80 or 7001;
        return /[^\.]{0,9}.chenlei\.me$/i.test(host) && (port === undefined || port === '7001');
      },
    }
  };

  return config;
};
